#
# Find the CppUnit includes and library
#
# This module defines
# CPPUNIT_INCLUDE_DIRS, where to find tiff.h, etc.
# CPPUNIT_LIBRARIES, the libraries to link against to use CppUnit.
# CPPUNIT_FOUND, If false, do not try to use CppUnit.

# also defined, but not for general use are
# CPPUNIT_LIBRARY, where to find the CppUnit library.
# CPPUNIT_DEBUG_LIBRARY, where to find the CppUnit library in debug mode.

message("[CPPUNIT]")
if(NOT CPPUNIT_ROOT)
	if(WIN32)
		find_path(TMP_CPPUNIT_PATH cppunit PATHS ${SDK_ROOT}/..)
		set(CPPUNIT_ROOT ${TMP_CPPUNIT_PATH}/cppunit/cppunit-1.12.1)
	else(WIN32)
		set(CPPUNIT_ROOT ${SDK_ROOT})
	endif(WIN32)
endif(NOT CPPUNIT_ROOT)
message("using cppunit: ${CPPUNIT_ROOT}")

set(CPPUNIT_INCLUDE_HINT ${CPPUNIT_ROOT}/include)
set(CPPUNIT_LIB_HINT ${CPPUNIT_ROOT}/lib)

list(APPEND CPPUNIT_INCLUDE_HINT /usr/local/include /usr/include)
list(APPEND CPPUNIT_LIB_HINT /usr/local/lib /usr/lib)

find_path(CPPUNIT_INCLUDE_DIRS cppunit/TestCase.h PATHS ${CPPUNIT_INCLUDE_HINT})

if(WIN32)
	#message("[Platform: windows]")
	#message("[DEBUG: ${CPPUNIT_INCLUDE_DIRS} ]")
	find_library(CPPUNIT_LIBRARY cppunit PATHS ${CPPUNIT_LIB_HINT})
	find_library(CPPUNIT_DEBUG_LIBRARY cppunitd PATHS ${CPPUNIT_LIB_HINT})
else(WIN32)
	#message("[Platform: unix]")
	# On unix system, debug and release have the same name
	find_library(CPPUNIT_LIBRARY cppunit PATHS ${CPPUNIT_LIB_HINT})
	find_library(CPPUNIT_DEBUG_LIBRARY cppunit PATHS ${CPPUNIT_LIB_HINT})
endif(WIN32)

if(CPPUNIT_INCLUDE_DIRS)
	if(CPPUNIT_LIBRARY)
		set(CPPUNIT_FOUND "YES")
		set(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ${CMAKE_DL_LIBS})
		set(CPPUNIT_DEBUG_LIBRARIES ${CPPUNIT_DEBUG_LIBRARY}
			${CMAKE_DL_LIBS})
	else(CPPUNIT_LIBRARY)
		message(SEND_ERROR "cppunit configure failed...")
	endif(CPPUNIT_LIBRARY)
endif(CPPUNIT_INCLUDE_DIRS)


